import { skipWaiting, clientsClaim, setCacheNameDetails } from 'workbox-core'
import { registerRoute  } from 'workbox-routing'
import {
    NetworkFirst, CacheFirst, StaleWhileRevalidate } from 'workbox-strategies'
import { CacheableResponsePlugin } from 'workbox-cacheable-response'
import {
    ExpirationPlugin
} from 'workbox-expiration'
import {
    precacheAndRoute,

} from 'workbox-precaching'

setCacheNameDetails({
    prefix: 'prefix',
    suffix: 'v1.0',
    precache: 'precache',
    runtime: 'runtime',
});

skipWaiting()
clientsClaim()

precacheAndRoute([
    '/',
    '/index.html',
    '/css/index.css',
    '/js/index.js',
    '/assets/fonts/graduate.eot',
    '/assets/fonts/graduate.ttf',
    '/assets/fonts/graduate.woff',
    '/assets/images/icon128.png',
    '/assets/images/icon144.png',
])

registerRoute(
    new RegExp(/^http:\/\/juheimg.oss-cn-hangzhou.aliyuncs.com/),
    new NetworkFirst({
        cacheName: 'images',
        plugins: [
            new CacheableResponsePlugin({
                statuses: [200],
            }),
            new ExpirationPlugin({
                maxEntries: 50,
                maxAgeSeconds: 60 * 60 * 24 * 30, // 30 Days
            }),
        ],
    }),
);



registerRoute(
    // ({ request }) => request.url === 'http://localhost:3030/api/food/getFoodList',
    new RegExp(/^http:\/\/localhost:3030/),
    new NetworkFirst({
        // cacheName: 'api',
        plugins: [
            new CacheableResponsePlugin({
                statuses: [200],
            }),
            new ExpirationPlugin({
                maxEntries: 50,
                maxAgeSeconds: 60 * 60 * 24 * 30, // 30 Days
            }),
        ],
    }),
);

